package se.prb.cheesymock;

/**
 * <h2>Summary</h2>
 * <p>
 * CheesyMockFactory is used to create mock objects within a spring configuration.
 * </p>
 *
 * <h2>Usage</h2>
 * <p>
 * To create a new mock object that implements a given interface:
 *
 * <pre>
 * 	<bean id="cheeseFactory" class="se.prb.cheesymock.CheesyMockFactory" />
 *
 * 	<bean id="myDelegate" class="my.package.MyDelegate" />
 *	<bean id="mockObjectId" factory-bean="cheeseFactory" factory-method="createMock">
 *	  <constructor-arg value="my.package.MyInterface" />
 *    <constructor-arg ref="myDelegate" />
 *   </bean>
 *
 * This corresponds the the code
 *
 * Object myDelegate = new MyDelegate();
 * MyInterface	mockObject	= (MyInterface) CheesyMock.createMock(MyInterface.class, myDelegate);
 * </pre>
 *
 * See {@link CheesyMock} for more information about the Mock objects.
 * </p>
 *
 * @author björn.Ekryd
 *
 */
public class CheesyMockFactory {
	public CheesyMockFactory() {
	}

	/**
	 * Convenience method: creates a new mock object without a delegate.
	 *
	 * @param interFaceToImplement
	 *            An interface to implement. This will be the expected return
	 *            type. Example 'java.lang.String'
	 * @return
	 */
	public Object createMock(String interfaceToImplement) throws ClassNotFoundException {
		return CheesyMock.createMock(Class.forName(interfaceToImplement));
	}

	/**
	 * Convenience method: creates a new mock object.
	 *
	 * @param interfaceToImplement
	 *            An interface to implement. This will be the expected return
	 *            type. Example 'java.lang.String'
	 * @param delegate
	 *            A delegate object that will receive all method calls made to
	 *            the mock object.
	 * @return
	 */
	public Object createMock(String interfaceToImplement, Object delegate) throws ClassNotFoundException {
		return CheesyMock.createMock(Class.forName(interfaceToImplement), delegate);
	}
}
